import { AxiosRequestConfig } from 'axios'
import serverApiUtils from '@/core/utils/serverApiUtils'
import lodash from 'lodash'
import { R } from '@/components/axios/interface'
import http from '@/components/axios/http'
import { CaptchaImageResponse } from '@/core/captcha/types/model/response/CaptchaImageResponse'
import captchaApiConfig from '@/core/captcha/apiconfig/captchaApiConfig'

class CaptchaImageServerApi {
	createBase64ByAppKey = (appToken: string, captchaAppKey: string): Promise<R<CaptchaImageResponse>> => {
		const config = lodash.merge(
			{
				data: { captchaAppKey: captchaAppKey },
				headers: serverApiUtils.addOnlyTokenHeader(appToken),
			} as AxiosRequestConfig,
			serverApiUtils.convertApiConfig(captchaApiConfig.createBase64ByAppKey),
		)

		return http.post(config)
	}
}

const captchaImageServerApi = new CaptchaImageServerApi()
export default captchaImageServerApi
